package com.java.test.system.gametfeemanage;


import com.java.test.controller.BaseController;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.dto.LoginAccountInfo;
import com.java.test.system.gametfeemanage.dto.GameFeeAddDTO;
import com.java.test.system.gametfeemanage.dto.GameFeeDTO;
import com.java.test.system.gametfeemanage.dto.GameFeeQueryDTO;
import com.java.test.system.gametfeemanage.dto.GameFeeUpdateDTO;
import com.java.test.system.gametfeemanage.vo.GameFeeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;

/**
 * 游戏抽水管理
 * @author lijie1
 */
@Slf4j
@RestController
@RequestMapping("/systemConfig/gameFeeManage")
public class GameFeeManageController extends BaseController {
    @Autowired
    GameFeeManageService gameFeeManageService;

    /**
     * 游戏抽水列表查询
     * @return
     */
    @RequestMapping(value = "/selectToList",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<GameFeeVO>> getGameFeeList(@RequestBody @Valid GameFeeQueryDTO queryDTO) {
        log.info("----------游戏抽水列表查询----------");
        return gameFeeManageService.getGameFeeList(queryDTO);
    }

    /**
     * 游戏抽水新增
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public ResponseDTO<String> addGameFee(@RequestBody @Valid GameFeeAddDTO addDTO, HttpServletRequest request) {
        log.info("----------游戏抽水添加----------");
        addDTO.setStatus(1);
        addDTO.setCreateTime(new Date());
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-抽水管理-抽水添加");
        addDTO.setOperation(user.getLoginAccout());
        return gameFeeManageService.addGameFee(addDTO);
    }

    /**
     * 通过id获取游戏抽水
     * @param dto
     * @return
     */
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    public ResponseDTO<GameFeeVO> selectById(@RequestBody @Valid GameFeeDTO dto) {
        log.info("----------游戏抽水查询----------");
        return gameFeeManageService.selectById(dto.getId());
    }

    /**
     * 修改游戏抽水
     * @param updateDTO
     * @return
     */
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public ResponseDTO<String> updateGameFee(@RequestBody @Valid GameFeeUpdateDTO updateDTO, HttpServletRequest request) {
        log.info("----------游戏类型修改----------");
        updateDTO.setModifyTime(new Date());
        updateDTO.setStatus(1);
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-抽水管理-抽水修改");
        return gameFeeManageService.updateGameFee(updateDTO);
    }

    /**
     * 通过id删除游戏抽水
     * @param dto
     * @return
     */
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public ResponseDTO<String> deleteById(@RequestBody @Valid GameFeeDTO dto, HttpServletRequest request) {
        log.info("----------游戏抽水删除----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-抽水管理-抽水删除");
        return gameFeeManageService.deleteById(dto.getId());
    }

}
